//
//  XMPPManager.h
//  RRT
//
//  Created by 涂操 on 15/2/10.
//  Copyright (c) 2015年 Asiainfo. All rights reserved.
//

#import <Foundation/Foundation.h>


#define SharedXMPPManager [XMPPManager sharedInstance]

//改用通知来传递im消息到各个界面
extern NSString * const Notification_IMReceiveChatTPMessage;
extern NSString * const Notification_IMReceiveGroupChatTPMessage;
extern NSString * const Notification_IMReceiveBeKickGroup;
extern NSString * const Notification_IMSendXmppMessageSuccess;
extern NSString * const Notification_IMSendXmppMessageFailed;
extern NSString * const Notification_IMCannotSendTPMessage;


typedef NS_ENUM(NSInteger, LoginIMFialCode) {
    LoginIMFial_NoJidOrPwd=0,           //账号或密码为空
    LoginIMFial_NetWorkDisconnect,      //网络连接断开了
    LoginIMFial_ConnectError,           //连接im服务器开始时出错
    LoginIMFial_ConnectTimeout,         //连接im服务器超时
    LoginIMFial_ConnectFail,            //连接im服务器失败
    LoginIMFial_AuthenticateError,      //验证密码开始时出错
    LoginIMFial_AuthenticateFail        //验证密码后验证失败
};

typedef void(^SuccessBlock)(id obj);
typedef void(^FaildBlock)(id obj,NSString *errorStr,LoginIMFialCode fialCode);


@protocol XMPPManagerDelegate <NSObject>

- (void)sendXmppMessageSuccess:(id)messageObj;     //发送消息成功
- (void)sendXmppMessageFailed:(id)messageObj;      //发送消息失败
- (void)cannotSendTPMessage:(id)messageObj;        //无法发送消息
- (void)receiveSingleChatMessage:(id)messageObj;   //收到私聊消息
- (void)receiveGroupChatMessage:(id)messageObj;    //收到群聊消息
- (void)receiveGroupBeKickGroup:(id)messageObj;    //收到被踢出群的消息

@end


@interface XMPPManager : NSObject

+ (instancetype)sharedInstance;

- (void)setupXmppStreamWithHost:(NSString *)hostName port:(NSString *)hostPortStr;

//登录im服务器
- (void)loginIMServerWithJID:(NSString *)myJid
                    password:(NSString *)myPwd
                     success:(SuccessBlock)success
                       error:(FaildBlock)faild;


- (BOOL)connect;

////退出并断开im服务器
//- (void)disconnectIMServer;
//
//- (void)disconnectXmpp;
//
//- (void)reconnectXmpp;
//
//- (void)reconnectServerByTimer;
//
//- (void)sendXMPPMessage:(XMPPMessage *)message;
//
//- (void)becomeActiveSendOnline;
//
//- (void)backgroundSendOffline;
//
////发送私聊信息
//- (void)sendMessageWithMessageID:(NSString *)msgID to:(NSString *)to body:(NSString *)body timestampStr:(NSString *)timestampStr;
//
////发送群聊信息
//- (BOOL)sendGroupMessageWithMessageID:(NSString *)msgID groupID:(NSString *)groupID body:(NSString *)body timestampStr:(NSString *)timestampStr;
//
////同时登录多个群组，传入多个群组的id
//- (void)loginGroupWithGroupArray:(NSArray *)groupIDArray ;
//
////登录某个群组
//- (void)loginGroupWithGroupID:(NSString *)groupID ;
//
////同时退出多个群组
//- (void)logoutGroupWithGroupArray:(NSArray *)groupIDArray ;
//
////退出某个群组
//- (void)logoutGroupWithGroupID:(NSString *)groupID;
//
////退出所有已登录的群组
//- (void)logoutAllGroup;
//
////检查是否已登录某群组
//- (BOOL)isLoginedGroupWithGroupID:(NSString *)groupID;


- (void)addDelegate:(id)delegate;
- (void)removeDelegate:(id)delegate;

@end
